package com.yst.sqlbuilder;

import com.yst.lambda.TableFieldFunc;

import java.util.Map;
import java.util.Objects;

public class SQLFieldExp<T> extends SQLField<T> implements IFieldExpression, ISQLExpression {
    private final TableFieldFunc<T,?> field;

    private final IAliasExpression tableAlias;


    public SQLFieldExp(IAliasExpression tableAlias,TableFieldFunc<T, ?> field) {
        super(tableAlias,field);
        this.tableAlias=tableAlias;
        this.field=field;
    }

    public SQLFieldExp(TableFieldFunc<T, ?> field, IAliasExpression tableAlias) {
        super(tableAlias,field);
        this.tableAlias=tableAlias;
        this.field=field;
    }

    @Override
    public String generateExpression(GenerateParam param) {
        return getRealField();
    }

    @Override
    public IEntitiesConfig getEntitiesConfig() {
        if (Objects.nonNull(tableAlias)) {
            return tableAlias.getEntitiesConfig();
        }
        else {
            return super.getEntitiesConfig();
        }
    }
}
